USE [NGroup_VTL_DB]
GO

/****** Object:  StoredProcedure [dbo].[AddNewProduct]    Script Date: 5/28/2015 9:59:17 PM ******/
DROP PROCEDURE [dbo].[AddNewProduct]
GO

/****** Object:  StoredProcedure [dbo].[AddNewProduct]    Script Date: 5/28/2015 9:59:17 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Bui Thanh Nam
-- Create date: 20131207
-- Description:	Add new product
-- =============================================
CREATE PROCEDURE [dbo].[AddNewProduct]
	
	@SupTypeID					INT,	
	@TypeID						INT,	
	@UniqueString				NVARCHAR(500),
	@HomePageDisplayBlockID		INT,
	@IsActive					BIT,
	@Title						NVARCHAR(500),
	@MetaContent				NVARCHAR(1500) = NULL,
	@MetaDescription			NVARCHAR(1500) = NULL,
	@Content					NVARCHAR(max) = NULL,
	@ProductDetail				NVARCHAR(max) = NULL,
    @DeliveryDetail				NVARCHAR(max),
	@ImageSmallURL				NVARCHAR(500),
	@ImageLargeURL				NVARCHAR(500),

	@TitleEn					NVARCHAR(500),
	@MetaContentEn				NVARCHAR(1500) = NULL,
	@MetaDescriptionEn			NVARCHAR(1500) = NULL,
	@ContentEn					NVARCHAR(max) = NULL,
	@ProductDetailEn			NVARCHAR(max) = NULL,    
	@ImageSmallURLEn			NVARCHAR(500),
	@ImageLargeURLEn			NVARCHAR(500),

	@CreatedAt					DATETIME,
	@CreatedBy					NVARCHAR(50),
	@Price						NVARCHAR(100),
	@PriceEn					NVARCHAR(100),
	@NewIdentity				INT = NULL OUTPUT

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF NOT EXISTS(
					SELECT * 
					FROM [dbo].[Products] WITH (NOLOCK) 
					WHERE [UniqueString] = @UniqueString
						  AND [IsActive] <> 0)
	BEGIN

		INSERT INTO [dbo].[Products]
			   ([TypeID]			   
			   ,[SupTypeID]			   
			   ,[UniqueString]
			   ,[MetaContent]
			   ,[MetaContent_En]
			   ,[MetaDescription]
			   ,[MetaDescription_En]
			   ,[IsActive]
			   ,[Title]
			   ,[Title_En]
			   ,[Content]
			   ,[ProductDetail]
			   ,[DeliveryDetail]
			   ,[ImageSmallURL]
			   ,[ImageLargeURL]

			   ,[Content_En]
			   ,[ProductDetail_En]			   
			   ,[ImageSmallURL_En]
			   ,[ImageLargeURL_En]

			   ,[CreatedAt]
			   ,[CreatedBy]			   
			   ,[HomePageDisplayBlockID]
			   ,[Price]
			   ,[Price_En])
		 VALUES(
				@TypeID			   
			   ,@SupTypeID			   
			   ,@UniqueString
			   ,@MetaContent
			   ,@MetaContentEn
			   ,@MetaDescription
			   ,@MetaDescriptionEn
			   ,@IsActive
			   ,@Title
			   ,@TitleEn
			   ,@Content
			   ,@ProductDetail
			   ,@DeliveryDetail
			   ,@ImageSmallURL
			   ,@ImageLargeURL
			   
			   ,@ContentEn
			   ,@ProductDetailEn			   
			   ,@ImageSmallURLEn
			   ,@ImageLargeURLEn

			   ,@CreatedAt
			   ,@CreatedBy			  
			   ,@HomePageDisplayBlockID
			   ,@Price
			   ,@PriceEn)
	END

	SELECT @NewIdentity = @@IDENTITY

END



GO


